package com.punai.config.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.punai.common.core.domain.TreeBo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.enums.BusinessType;
import com.punai.config.domain.ConfigInventoryChapter;
import com.punai.config.service.IConfigInventoryChapterService;
import com.punai.common.utils.poi.ExcelUtil;
import com.punai.common.core.page.TableDataInfo;

/**
 * 清单库Controller
 * 
 * @author zxw
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/config/inventoryChapter")
public class ConfigInventoryChapterController extends BaseController
{
    @Autowired
    private IConfigInventoryChapterService configInventoryChapterService;

    /**
     * 查询清单库列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigInventoryChapter configInventoryChapter)
    {
        startPage();
        List<ConfigInventoryChapter> list = configInventoryChapterService.selectConfigInventoryChapterList(configInventoryChapter);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:list')")
    @GetMapping("/treelist")
    public AjaxResult treelist(ConfigInventoryChapter configInventoryChapter)
    {
        List<TreeBo> list = configInventoryChapterService.treelist(configInventoryChapter,getCompanyId());
        return AjaxResult.success(list);
    }



    /**
     * 获取清单库详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(configInventoryChapterService.selectConfigInventoryChapterById(id));
    }

    /**
     * 新增清单库
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:add')")
    @Log(title = "清单库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigInventoryChapter configInventoryChapter)
    {
        configInventoryChapter.setCompanyId(getCompanyId());
        return toAjax(configInventoryChapterService.insertConfigInventoryChapter(configInventoryChapter));
    }

    /**
     * 修改清单库
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:edit')")
    @Log(title = "清单库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigInventoryChapter configInventoryChapter)
    {
        return toAjax(configInventoryChapterService.updateConfigInventoryChapter(configInventoryChapter));
    }

    /**
     * 删除清单库
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventoryChapter:remove')")
    @Log(title = "清单库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(configInventoryChapterService.deleteConfigInventoryChapterByIds(ids));
    }
}
